package itsm.isperp.module.controller.sparepartOld;

import itsm.isperp.framework.core.context.ContextHolder;
import itsm.isperp.framework.web.controller.BaseController;
import itsm.isperp.framework.web.response.ResultMessage;
import itsm.isperp.module.entity.sparepart.SptSparepartChangeDetail;
import itsm.isperp.module.service.sparepart.SptSparepartChangeDetailService;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 备件管理控制器
 * 
 * @author lizx
 * @date 2013-9-12
 */
@Controller
@RequestMapping("sparepart/sparepartChangeDetail/old")
public class SptSparepartChangeDetailOldController extends
		BaseController<SptSparepartChangeDetail> {

	@Autowired
	protected SptSparepartChangeDetailService sptSparepartChangeDetailService;

	@Override
	public SptSparepartChangeDetailService getService() {
		return sptSparepartChangeDetailService;
	}

	@Override
	public String getPageTitle() {
		return "备件采购项管理";
	}

	@RequestMapping("saveDetails")
	@ResponseBody
	public ResultMessage saveDetails(String relationId, String sparepartIds,String typeKey) {
		String[] sparepartIdArr = sparepartIds.split(",");
		sptSparepartChangeDetailService.batchSave(relationId, sparepartIdArr,typeKey);
		return ResultMessage.success();
	}

	@RequestMapping("listDetails")
	@ResponseBody
	public List<Map<String, Object>> listDetails(String relationId) {

		return this.sptSparepartChangeDetailService
				.findAllDetailByRelationId(relationId);
	}
	
	@RequestMapping("deleteByRelationIdAndSpaId")
  @ResponseBody
  public ResultMessage deleteByRelationIdAndSpaId(String relationId) {
	  String sql="delete from spt_sparepart_change_detail where relation_id='"+relationId+"'";
	  JdbcTemplate jdbcTemplate=ContextHolder.getSpringBean("jdbcTemplate");
	  jdbcTemplate.execute(sql);
   return ResultMessage.success();
  }

}
